<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\DB;

class CreateTopicsTable extends Migration
{
	private $tableName = 'topics';
	private $tableComment = '众筹主题表';
	private $primaryKey = 'id';

	/**
	 * Run the migrations.
	 *
	 * @return void
	 */
	public function up()
	{
		Schema::create($this->tableName, function (Blueprint $table) {
			$table->increments(env('DB_CONNECTION') == 'oracle' ? strtoupper($this->primaryKey) : $this->primaryKey)->comment('众筹id');
			$table->string('banners', 100)->comment('轮播图')->nullable();
			$table->string('title', 50)->comment('标题描述')->nullable();
			$table->string('desc', 30)->comment('描述')->nullable();
			$table->unsignedInteger('status')->comment('状态1：正常2：删除，0下架')->default(1);
			$table->unsignedInteger('share_id')->comment('分享id')->default(0);
			$table->string('share_img')->comment('分享主图')->nullable();
			$table->mediumText('content')->comment('众筹详情')->nullable();
			$table->mediumText('rules')->comment('参赛规则')->nullable();
			$table->mediumText('infos')->comment('用户须知')->nullable();
			$table->mediumText('shares')->comment('分销须知')->nullable();
			$table->string('money',10)->comment('众筹金额')->nullable();
			$table->Integer('num')->comment('众筹人数')->default(1);
			$table->Integer('times')->comment('访问量')->default(0);
			$table->Integer('joins')->comment('参加量')->default(0);
			$table->string('rates1',10)->comment('一级用户返佣金比列')->nullable();
			$table->string('rates2',10)->comment('二级用户返佣金比列')->nullable();
			$table->timestamp('start_date')->comment('开始时间')->nullable();
			$table->timestamp('end_date')->comment('结束时间')->nullable();
			$table->timestamp('start')->comment('活动开始')->nullable();
            $table->timestamps();

			if (env('DB_CONNECTION') == 'oracle') {
				$table->comment = $this->tableComment;
			}
		});

		if (env('DB_CONNECTION') == 'mysql') {
			DB::statement("ALTER TABLE `" . DB::getTablePrefix() . $this->tableName . "` comment '{$this->tableComment}'");
		}
	}

	/**
	 * Reverse the migrations.
	 *
	 * @return void
	 */
	public function down()
	{
		Schema::dropIfExists($this->tableName);
		if (env('DB_CONNECTION') == 'oracle') {
			$sequence = DB::getSequence();
			$sequence->drop(strtoupper($this->tableName . '_' . $this->primaryKey . '_SEQ'));
		}
	}
}
